package com.sample.mockito.test;

import com.sample.mockito.Person;
import com.sample.mockito.PersonGroup;
import org.junit.Before;
import org.junit.Test;
import org.mockito.*;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class SampleTest06 {

    @InjectMocks
    private static PersonGroup personGroup;

    @Spy
    private static LinkedList group;

    @Captor
    ArgumentCaptor<Person> captor;


    @Before
    public void setUp(){
        MockitoAnnotations.initMocks(this);
    }


    @Test
    public void sampleTest21(){
        List<Person> persons = new ArrayList<Person>();
        Person person = new Person();
        person.setId(3l);
        person.setName("sdfsdf");
        personGroup.addPerson(person);

        //1
        System.out.println(personGroup.size());

        when(group.size()).thenReturn(100);

        //100
        System.out.println(personGroup.size());

        verify(group).add(captor.capture());
        //Person{id=3, name='sdfsdf'}
        System.out.println(captor.getValue());
    }
}